﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CSharpFunctionalExtensions;
using HandyControl.Tools.Extension;
using System;

namespace FunasrSTT.Translate.ViewModels;

/// <summary>
/// 询问对话框视图模型.
/// </summary>
[INotifyPropertyChanged]
public partial class ConfirmViewModel : IDialogResultable<Result>
{
    /// <summary>
    /// 询问对话框标题.
    /// </summary>
    [ObservableProperty] private string _title = string.Empty;

    /// <summary>
    /// 询问对话框 `确认` 按钮文本.
    /// </summary>
    [ObservableProperty] private string _confirmText = string.Empty;

    /// <summary>
    /// 询问对话框 `取消` 按钮文本.
    /// </summary>
    [ObservableProperty] private string _cancelText = string.Empty;

    /// <summary>
    /// 询问对话框消息文本.
    /// </summary>
    [ObservableProperty] private string _message = string.Empty;

    /// <inheritdoc />
    public Result Result { get; set; } = Result.Failure("Canceled");

    /// <inheritdoc />
    public Action? CloseAction { get; set; }

   
    public void Initialize(
        string title,
        string message,
        string confirmText,
        string cancelText)
    {
        Title       = title;
        Message     = message;
        ConfirmText = confirmText;
        CancelText  = cancelText;
    }

    /// <summary>
    /// 取消.
    /// </summary>
    [RelayCommand]
    private void Cancel()
    {
        CloseAction?.Invoke();
    }

    /// <summary>
    /// 确认.
    /// </summary>
    [RelayCommand]
    private void Confirm()
    {
        Result = Result.Success();
        CloseAction?.Invoke();
    }
}
